<?php

namespace App\Module\Api\Controllers;
use App\Module\Api\Controllers\Request\SmsCodeRequest;
use App\Module\Api\Validator\SmsCodeValidator;
use App\System\Base\Services\TokenService;
use App\System\Base\Services\SmsService;
use App\System\Cis\Repositories\CisUserRepository;

/**
 *发送验证码
 */
class SmsCodeController extends Controller
{

    public function __construct()
    {
        $this->query = new SmsCodeRequest();
        parent::__construct();

    }

    public function index()
    {
        (new SmsCodeValidator())->check();
         TokenService::getUserId();
         $master_id = TokenService::getMasterId();
         $sms = SmsService::getInstance();
         if($this->query->type == 7)
         {
             $user = CisUserRepository::getInstance();
             $user_info = $user->getUser($master_id);
             $this->query->mobile = $user_info->mobile;
         }
         if($this->query->action == 1)
         {
             $res = $sms->SmsSend($this->query->mobile,$this->query->type);
         }
         else
         {
             $res = $sms->VerifySmsCode($this->query->mobile,$this->query->code,$this->query->type);
         }

        return apiResponse($res);
    }
}
